﻿using System;
using System.Data.Entity;
using System.Windows.Forms;
using AppAcc.Models;

namespace AppAcc.Views.DanhMuc
{
    public partial class FormNhomTaiSanCapNhap : DevComponents.DotNetBar.RibbonForm
    {
        //private AppAccContext db = new AppAccContext();
        private PhanMenKeToanEntities1 db = new PhanMenKeToanEntities1();
        public int id = 0;
        public FormNhomTaiSanCapNhap()
        {
            InitializeComponent();
        }

        private void BttLuu_Click(object sender, EventArgs e)
        {
            Edit(id);
        }

        private void BttThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FormNhomTaiSanCapNhap_Load(object sender, EventArgs e)
        {
            if (id!=0)
            {
                var t = db.NhomTaiSans.Find(id);
                txtTenNhomTaiSan.Text = t.TenNhomTaiSan;
                txtDienGiai.Text = t.DienGiai;
            }
            else
            {
                MessageBox.Show("Không lấy được dữ liệu!");
            }
        }
        void Edit(int id = 0)
        {
            try
            {
                var nts = db.NhomTaiSans.Find(id);
                nts.TenNhomTaiSan = txtTenNhomTaiSan.Text;
                nts.DienGiai = txtDienGiai.Text;
                db.Entry(nts).State = EntityState.Modified;
                db.SaveChanges();
                this.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
    }
}
